Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Public Class f_DCTDevPreparation
    Dim objhdlr As New Cls_DCTDevHdlr
    Public Shared f As String
    Private Sub f_DCTDevPreparation_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim str As String
        Dim strcontents As String
        strcontents = ""
        Dim strtemp As String = ""
        str = "data source=.;initial catalog=master;persist security info=False;user id=realm;password=friend;packet size=4096"
        Dim objcmd As New SqlCommand
        Dim objreader As StreamReader
        Dim objcon As New SqlConnection(str)
        objcmd.Connection = objcon
        objcon.Open()

        objreader = New StreamReader("ExecGetDbnames.sql")
        objcmd.CommandTimeout = 700
        strtemp = objreader.ReadLine
        Do
            If strtemp <> "GO" Then
                strcontents = strcontents + ControlChars.CrLf + strtemp
            Else
                objcmd.CommandText = strcontents.Trim
                objcmd.ExecuteNonQuery()
                strcontents = ""
            End If
            strtemp = objreader.ReadLine
        Loop While Not strtemp Is Nothing
        objreader.Close()
        Dim ds As New DataSet
        ds = objhdlr.GetAllDbNames(str)
        ddlDbName.DataSource = ds.Tables(0)
        ddlDbName.DisplayMember = "name"
        ddlDbName.ValueMember = "dbid"
        objcon.Close()
        objcon.Dispose()
        objcon = Nothing
        f_DCTDevMenu.MainMenuTableSelection.Enabled = True
        f_DCTDevMenu.MainMenuSpecialSettings.Enabled = True
        f_DCTDevMenu.MainMenuScriptGeneration.Enabled = True
    End Sub

    Private Sub btnPrepare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrepare.Click
        If ddlDbName.SelectedIndex <> 0 Then
            prgbar.Minimum = 0
            prgbar.Maximum = 100
            prgbar.Step = 20
            prgbar.PerformStep()
            Dim strConString As String = "data source=.;initial catalog=" & ddlDbName.Text & ";persist security info=False;user id=realm;password=friend;packet size=4096"
            Dim strcontents As String
            strcontents = ""
            Dim strtemp As String = ""
            Dim objcmd As New SqlCommand
            Dim objreader As StreamReader
            Dim objcon As New SqlConnection(strConString)
            prgbar.PerformStep()
            objcmd.Connection = objcon
            objcon.Open()
            objreader = New StreamReader("Prepare for DCT dev.sql")
            objcmd.CommandTimeout = 700
            prgbar.PerformStep()
            strtemp = objreader.ReadLine
            Do

                If strtemp <> "GO" Then
                    strcontents = strcontents + ControlChars.CrLf + strtemp
                Else
                    objcmd.CommandText = strcontents.Trim
                    objcmd.ExecuteNonQuery()
                    strcontents = ""
                End If
                strtemp = objreader.ReadLine
            Loop While Not strtemp Is Nothing
            prgbar.PerformStep()
            objreader.Close()
            prgbar.PerformStep()
            MessageBox.Show("Database ready for DCT Development")
            f = ddlDbName.Text
            Me.Hide()
        Else
            MessageBox.Show("Please Select Database ")
        End If
    End Sub

    Private Sub btncontinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncontinue.Click
        If ddlDbName.SelectedIndex <> 0 Then
            f = ddlDbName.Text
            Me.Hide()
        Else
            MessageBox.Show("Please Select Database ")
        End If
    End Sub
End Class